/**
 * Created by kaqu on 09/03/15.
 */



var loader = new createjs.LoadQueue();
loader.addEventListener("fileload", handleFileComplete);

var assetArray = [];

function loadGraphics() {
    loader.loadFile({id: "LetterA", src: "assets/EmptyHex.png"});

}
function handleFileComplete(event) {
    assetArray[assetArray.length] = event.result;
    //console.log(assetArray);
    //TEST!!! TODO
    var sample = new HEX.gameField(10, 10);

    //for (var i = 0; i < sample.fields.length; ++i) {
    //    var c = "";
    //    for (var j = 0; j < sample.fields[i].length; ++j) {
    //
    //        c += sample.fields[i][j].toString() + " ";
    //    }
    //    console.log(c);
    //}
    //console.log(sample.fields[1][2].toString());
    //console.log(sample.fields[1][2].neighbors);
    for (var i = 0; i < sample.fields.length; ++i) {
        for (var j = 0; j < sample.fields[i].length; ++j) {
            paintHex(i, j);
        }
    }
    //TEST!!! TODO
}


function paintHex(x, y) {
    var holdImage = new createjs.Bitmap(assetArray[0]);
    holdImage.x = hexPixelSize[0] * x;
    holdImage.y = hexPixelSize[1] * y;
    if (x % 2 == 1) {
        holdImage.y += hexPixelSize[2];
    }
    holdImage.alpha = 1;
    stage.addChild(holdImage);
    if (graphicsDebugMode) {
        var text = new createjs.Text("(" + x + "," + y + ")", "9px Arial", "#ff7700");
        text.x = hexPixelSize[0] * x + 20;
        text.y = hexPixelSize[1] * y + 26;
        if (x % 2 == 1) {
            text.y += hexPixelSize[2];
        }
        stage.addChild(text);
    }
    stage.update();
    //console.log("hex " + x + " " + y + " painted");
}

